<template>
	<view class="container">
		<!-- 个人信息 -->
		<view class="userinfo bg-blue text-white uni-flex uni-row p-30 fs14">
			<view class="flex-item">
				<image class="userinfo_avatar bg-white" :src="userInfo.wechat && userInfo.wechat.headimgurl ? userInfo.wechat.headimgurl : '/static/avatar.png'" mode="aspectFill"></image>
			</view>
			<view class="flex-item w-70">
				<view v-if="userInfo.id">
					<view class="userinfo_name m-20">{{userInfo.wechat && userInfo.wechat.nickname ? userInfo.wechat.nickname : userInfo.realname}}</view>
					<view class="userinfo_phone m-20">{{userInfo.phone}}</view>
				</view>
				<view v-else>
					<view class="user_login_btn" @click="goPage('login', '')">登录</view>
				</view>
			</view>
			<view class="flex-item justify-right m-t20 fs12" v-if="userInfo.id">
				<uni-icons class="" type="gear-filled" size="18" color="#ffffff" @click="goPage('setting', '')"></uni-icons>
			</view>
		</view>
		
		<view class="ad_image" v-if="adData && adData.list.length > 0">
			<!--广告位-->
			<cc-swiper :info="adData"></cc-swiper>
		</view>
		
		<view class="m-t20 m-l30 m-r30">
			<view v-for="item in houseList" class="bg-white p-20 round-10 m-t20 fs14 pos_relative">
				<view class="uni-flex justify-space-between p-t10 p-b10 m-b30 border-b1">
					<view class="w-70 text-row fs15">{{ item.customer.DecorationFullAddress || "" }}</view>
					<view class="w-30 uni-flex justify-right">
						<!-- <view class="text-red fs12 fw600">{{ serviceState[item.sState] }}</view> -->
					</view>
				</view>
				<view class="p-b20">户型：{{ item.customer.HouseType || "" }}</view>
				<view class="p-b20">面积：{{ item.customer.Area || 0 }}㎡</view>
				<view class="uni-flex justify-right m-t10 border-t1">
				<view class="btn_small_green m-r10" @click="goPage('design', info.Vr_Url)" v-if="info.Vr_Url"> VR图 </view>
				<view class="btn_small_green m-r10" @click="goPage('design', info.D3_Url)" v-if="info.D3_Url"> 3D图 </view>
					<view class="m-t20 btn_small_green m-r20" @click="goPage('sales', item.CustomerNo)"> 投诉 </view>
					<view class="m-t20 btn_small" @click="goPage('service', item.CustomerNo)"> 详情 </view>
				</view>
			</view>
		</view>
		
		<common-footer></common-footer>
	</view>
</template>
<script>
import { logout, userinfo, getAd } from "@/api/base.js"
import { getServiceList } from "@/api/project.js"
let that;
export default {
	data() {
		return {
			userInfo: "",		//用户信息	
			menus: [],	//菜单
			houseList: [],	//我的房子
			serviceState: ['待开工','在建','在建','已完工'],
			adData: {
				list: [],
				imgWidth: "100%",
				imgHeight: "100px",
				field: "title"
			}
		}
	},
	onLoad(){
		that = this
		this.getUserInfo()
		this.getList()
		this.getAdList()
	},
	methods: {
		getList(){			
			let params = {
				page: 1,
				size: 20,
				from: "weminicut"
			};
			that.houseList = []
			getServiceList(params).then((res)=>{
				that.houseList = res.data.list;
			})
		},
		/**
		 * 获取用户信息
		 */
		getUserInfo(){
			let that = this
			that.userInfo = ""
			userinfo().then((res) => {
				if(res.data && res.data.wechat && res.data.id) {
					that.userInfo = res.data
				}else {
					that.userInfo = uni.getStorageSync("userinfo")
				}
			})
		},
		/**
		 * 广告
		 */
		getAdList(){
			getAd({
				order: "sort asc",
				condition: {
					state: 1,
					position_code: "myTopBanner",
				}				
			}).then(res => {
				that.adData.list = res.data
			})
		},
		goPage(type, content) {
			if(type == "login") {
				uni.navigateTo({
					url: `/pages/user/login`
				})		
				return				
			}
			else if(type == "setting") { //编辑
				uni.navigateTo({
					url: `/pages/user/setting`
				})			
				return
			}
			if(content=="") {
				uni.showToast({ title: '工地信息异常，请联系我们', icon: 'none' })
				return;
			}
			if(type == "service") { //工地详情		
				uni.navigateTo({
					url: `/pages/index/service?customerno=${content}`
				})
			}else if(type == "design") { //效果图		
				uni.navigateTo({
					url: `/pages/index/design?url=${encodeURIComponent(content)}`
				})				
			}else if(type == "sales") { //工地售后列表
				uni.navigateTo({
					url: `/pages/mine/saleslist?CustomerNo=${content}`
				})								
			}
			
		},
	}
}
</script>
<style>
@import '@/common/uni-nvue.css';
.userinfo_avatar {
	width: 80px;
	height: 80px;
	border-radius: 50%;
}
.logout {
	position: relative;
	top: 26vh;
	background-color: #eee;
	width: 100%;
	padding: 12px 0;
	text-align: center;
	border-radius: 20rpx;
	color: #555;
}
.mode_right {
	position: absolute;
	top: 50%;
	right: 10px;
}
.ad_image {
	margin: 30rpx;
}
.swiper-box {
	min-height: 200rpx;
}
.swiper-item {
	width: 100%;
	height: 100%;
	
}
.ad_img {
	width: 100%;
	height: 100%;
}
.user_login_btn {
	background-color: rgba(255, 255, 255, .8);
	border-radius: 50px;
	height: 32px;
	line-height: 32px;
	width: 120px;
	text-align: center;
	color: #007AFF;
	margin: 40rpx 0 0 30rpx;
}
</style>